package com.zdy.im.user.controller;


import com.sixeco.framework.common.api.ApiDoc;
import com.sixeco.framework.common.enums.SysResultCodeEnum;
import com.sixeco.framework.http.data.vo.HttpRequestByIdVo;
import com.sixeco.framework.http.data.vo.ResponseResultList;
import com.sixeco.framework.http.handler.OutputResponse;
import com.zdy.im.user.ImErrorMsg;
import com.zdy.im.user.UrlCommand;
import com.zdy.im.user.dto.response.ImUserGroupInfoResponseDto;
import com.zdy.im.user.facade.ImUserGroupInfoFacade;
import com.zdy.im.user.service.ImUserGroupInfoService;
import com.zdy.im.user.vo.request.ImUserGroupQueryRequestVo;
import com.zdy.im.user.vo.request.UserGroupInfoRequestVo;
import com.zdy.im.user.vo.response.ImUserGroupInfoShowResponseVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @Title: ImUserGroupInfoController.java
 * @Author 作者 : zdy
 * @CreateDate 创建时间: 2021-02-30
 * @version V1.0
 *  <pre>
 * 修改记录
 *    修改后版本:     修改人：  修改日期:     修改内容:
 * </pre>
 * @Description: TODO(说明) 对象缓存统一模板实现类;
 */
@ApiDoc(
        module = "用户好友分组表模块", isApp = true
)
@Controller
public class ImUserGroupInfoController {

    @Autowired
    private ImUserGroupInfoFacade imUserGroupInfoFacade;

    @Autowired
    private ImUserGroupInfoService imUserGroupInfoService;


    /**
    * @Title: test测试生成类分页信息
    * @Description:testRequestVo @{Link TestRequestVo}
    * @param
    * @return
    * @throw
    * @author suven
    * @date 2019-07-19 13:16:48
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    /*@ApiDoc(
            value = "分页获取用户好友分组表信息",
            request = ImUserGroupInfoQueryRequestVo.class,
            response = ImUserGroupInfoShowResponseVo.class
    )
    @RequestMapping(value = UrlCommand.user_imUserGroupInfo_pageList, method = RequestMethod.GET)
    public void list(OutputResponse out, ImUserGroupInfoQueryRequestVo imUserGroupInfoQueryRequestVo){
            ImUserGroupInfoRequestDto imUserGroupInfoRequestDto = ImUserGroupInfoRequestDto.build( ).clone(imUserGroupInfoQueryRequestVo);

        BasePage page =  BasePage.build().toPageSize(imUserGroupInfoQueryRequestVo.getPageSize()).toPageNo(imUserGroupInfoQueryRequestVo.getPageNo());
        page.toParamObject(imUserGroupInfoRequestDto );
        ResponseResultList<ImUserGroupInfoResponseDto> resultList = imUserGroupInfoService.getImUserGroupInfoByNextPage(page);

        if(null == resultList || resultList.getList().isEmpty() ){
            out.writeSuccess();
            return;
        }
        List<ImUserGroupInfoShowResponseVo> listVo = new ArrayList<>();
        resultList.getList().forEach(e -> listVo.add(ImUserGroupInfoShowResponseVo.build().clone(e)));

        ResponseResultList list =  ResponseResultList.build().toList(listVo)
                .toIsNextPage(resultList.getIsNextPage())
                .toPageIndex(resultList.getPageIndex())
                .toTotal(resultList.getTotal());
        out.write(list);
    }*/





    /**
    * @Title: 查看test测试生成类信息
    * @Description:testRequestVo @{Link TestRequestVo}
    * @param
    * @return
    * @throw
    * @author suven
    * @date 2019-07-19 13:16:48
    *  --------------------------------------------------------
    *  modifyer    modifyTime                 comment
    *
    *  --------------------------------------------------------
    */
    @ApiDoc(
            value = "查看用户好友分组表信息",
            request = HttpRequestByIdVo.class,
            response = ImUserGroupInfoShowResponseVo.class
    )
    @RequestMapping(value = UrlCommand.user_imUserGroupInfo_info ,method = RequestMethod.GET)
    public void detail(OutputResponse out, HttpRequestByIdVo idRequestVo){

            ImUserGroupInfoResponseDto imUserGroupInfoResponseDto = imUserGroupInfoService.getImUserGroupInfoById(idRequestVo.getId());
            ImUserGroupInfoShowResponseVo vo =  ImUserGroupInfoShowResponseVo.build().clone(imUserGroupInfoResponseDto);
        out.write(vo);
    }

    @ApiDoc(
            value = "用户添加组",
            request = UserGroupInfoRequestVo.class,
            response = boolean.class
    )
    @RequestMapping(value = UrlCommand.user_imUserGroupInfo_save ,method = RequestMethod.POST)
    public void save(OutputResponse out, UserGroupInfoRequestVo userGroupInfoRequestVo){
        if (userGroupInfoRequestVo.getUserId() == 0) {
            out.write(SysResultCodeEnum.SYS_WEB_ID_INFO_NO_EXIST);
            return ;
        }
        if (StringUtils.isEmpty(userGroupInfoRequestVo.getGroupName())) {
            out.write(SysResultCodeEnum.SYS_PARAM_ERROR.formatMsg(ImErrorMsg.User.USER_GROUP_NAME_NULL));
            return ;
        }
        boolean res = imUserGroupInfoFacade.save(userGroupInfoRequestVo);
        out.write(res);
    }

    @ApiDoc(
            value = "删除某个组",
            request = HttpRequestByIdVo.class,
            response = Integer.class
    )
    @RequestMapping(value = UrlCommand.user_imUserGroupInfo_del,method = RequestMethod.POST)
    public  void  del(OutputResponse out, HttpRequestByIdVo httpRequestByIdVo){
        if (httpRequestByIdVo.getId() == 0 ) {
            out.write(SysResultCodeEnum.SYS_WEB_ID_INFO_NO_EXIST);
            return ;
        }
        int result = imUserGroupInfoFacade.del(httpRequestByIdVo.getId());
        out.write(result);
    }

    @ApiDoc(
            value = "查询某用户下，所有组列表信息",
            request = ImUserGroupQueryRequestVo.class,
            response = ImUserGroupInfoShowResponseVo.class
    )
    @RequestMapping(value = UrlCommand.user_imUserGroupInfo_list, method = RequestMethod.GET)
    public void getlist(OutputResponse out, ImUserGroupQueryRequestVo imUserGroupQueryRequestVo){
        ResponseResultList<ImUserGroupInfoShowResponseVo> resultList = imUserGroupInfoFacade.selectListByUserId(imUserGroupQueryRequestVo.getUserId());
        out.write(resultList);
    }

}
